<%--
  Created by IntelliJ IDEA.
  User: yang0
  Date: 2023/6/1
  Time: 15:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>CoolMeeting会议管理系统</title>
    <link rel="stylesheet" href="styles/common.css"/>
    <script>

        var xmlHttp;
        function createXMLHttpRequest(){
            if(window.ActiveXObject){
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }else if(window.XMLHttpRequest){
                xmlHttp = new  XMLHttpRequest();
            }
        }
        var inputvalue1;
        var val1;
        function edit(btn){
            //创建 input1 ==  text
            var input1 = document.createElement("INPUT");
            input1.setAttribute("type","text");
            //将td的值付给 input1  ，获取部门名称赋值给input
            var td = btn.parentNode.parentNode.children[1];
            var tdv = td.innerHTML;
            td.innerHTML = "";
            input1.setAttribute("value",tdv);
            input1.setAttribute("onblur","btnclick(this)");
            td.appendChild(input1);
            val1 = btn.nextElementSibling.value;
            //console.log(btn)
            btn.disabled = true;

        }

        function btnclick(inp){
            //alert('111111111111');
            inputvalue1 = inp.value;
            createXMLHttpRequest();
            var url = "addDeleteDepartmentServlet?code=edit&departmentid=" + val1+"&departmentname="+ inputvalue1;
            xmlHttp.open('get',url,false);
            //xmlHttp.onreadystatechange = callback;
            xmlHttp.send(null);
            window.location.reload();
        }
    </script>
</head>
<body>
<div class="page-body">
    <div class="page-content">
        <div class="content-nav">
            人员管理 > 部门管理
        </div>
        <form action="addDeleteDepartmentServlet" method="post">
            <fieldset>
                <legend>添加部门</legend>
                部门名称:
                <input type="text" name="departmentname" maxlength="20"/>
                <input type="hidden" name="code" value="add">
                <input type="submit" class="clickbutton" value="添加"/>
            </fieldset>
        </form>
        <table class="listtable">
            <caption>所有部门:</caption>
            <tr class="listheader">
                <th>部门编号</th>
                <th>部门名称</th>
                <th>操作</th>
            </tr>
            <c:forEach var="department" items="${requestScope.departmentList}">
                <tr>
                    <td>${department.departmentid}</td>
                    <td>${department.departmentname}</td>
                    <td>
                        <input type="button" class="clickbutton" onclick="edit(this)" value="编辑">
                            <%--<a class="clickbutton" onclick="edit(this)">编辑</a>--%>
                        <input type="hidden" name="empid" value="${department.departmentid}">
                        <a class="clickbutton"
                           href="addDeleteDepartmentServlet?code=delete&departmentid=${department.departmentid}">删除</a>
                    </td>
                </tr>
            </c:forEach>


        </table>
    </div>
</div>
</body>
</html>
